package com.zhiyi.app.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

@EnableSwagger2
@Configuration
@EnableWebMvc
@ComponentScan("com.zhiyi.app.controller")
public class SwaggerConfig {

    @Bean
    public Docket create(){
        return new Docket(DocumentationType.SWAGGER_2)
//                会放置API的信息
                .apiInfo(apiInfo())
                .select()
//                扫描controller所在的包
                .apis(RequestHandlerSelectors.basePackage("com.zhiyi.app.controller"))
//                代表路径
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo(){
        return new ApiInfoBuilder()
                .title("APP信息管理平台api文档")
                .description("供前段开发人员使用的后台接口文档")
                .version("v1.0.0")
                .build();
    }
}
